#include "common_api.h"

void SYS_Init(void)
{
	clock_init();	//时钟初始化
	WDT_Init();		//看门狗
	InitData();		//用flash模拟ee
	
}
    
void ms10Work(void)
{


}

void ms30Work(void)
{



}
void ms100Work(void)
{

    Measure_OilTem ();      //测油温
    Measure_OilLevel ();    //测油位
    Measure_Step ();         //测步长
	
}
void ms300Work(void)
{

	Motor_Move();
	
}
void ms500Work(void) //can发送数据
{
//	CanSendWork();
//	DPF_CHECK();		//国四再生状态判断
}
void secondWork(void)
{
	WorkingTime();
	DisplayTime(Monitor_Work_Time);
	Alarm_Work();

	
}
 
void Alarm_Work(void)
{

	//油水分离	
	if(OIL_WATER_STATE ==0)
	{
		OIL_WATER_LED = 1;
	}
	else
	{
		OIL_WATER_LED = 0;
	}
    //预热报警
    if(PREHEAT_STATE == 0)
	{
		PREHEAT_LED = 1;
	}
	else
	{
		PREHEAT_LED = 0;
	}
	//机油压力
	if(OilPressure == 0)
	{
		OilPressure_LED = 1;
	}
	else
	{
		OilPressure_LED = 0;
	}
	//油位
    if (OilLevelAD < 200)     //油位低于1/8
    {
        if (TIME_CNT.oil_level_count >= 3)
        {
            Alarm_Visible_flag.oil_level = 1;

        }
        else
        {
            TIME_CNT.oil_level_count++;
        }
    }
    else
    {
        TIME_CNT.oil_level_count = 0;
        Alarm_Visible_flag.oil_level = 0;
    }
    if (Alarm_Visible_flag.oil_level == 1)
    {

		OiLLevel_LED = 1;
    }
	else
	{
		 OiLLevel_LED = 0; 
	}

    /*************************空档**************************************************/
    if (KongDang == 0)
    {
        KongDang_LED = 1;
    }
    else
    {
        KongDang_LED = 0;
    }
    /*************************油温国二低有效**************************************************/
    if (OilTemAD < 500)
    {
        OiLTem_LED  = 1;
    }
    else
    {
        OiLTem_LED = 0;
    }
	/*************************货叉锁定**************************************************/
	if (Lock == 0)
    {
        Lock_LED = 1;
    }
    else
    {
        Lock_LED = 0;
    }
	/*************************故障**************************************************/
	if (Engine_Guzhang == 0)
    {
        Guzhang_LED = 1;
    }
    else
    {
        Guzhang_LED = 0;
    }
	/*************************充电**************************************************/
	if (ChongDian == 0)
    {
        ChongDian_LED = 1;
		OIL_WATER_LED = 1;
		Lock_LED = 1;	
    }
    else
    {
        ChongDian_LED = 0;
		OIL_WATER_LED = 0;
		Lock_LED = 0;	
    }
#if 0   //检测IO口故障状态
     if( ECU_ERROR_IN == 0 )//接地报警
     {
         if ( TIME_CNT.ecu_err_count >= 5 )
         {
             Alarm_Visible_flag.ecu_err = 1;
         }
         else
         {
             TIME_CNT.ecu_err_count++;
         }
     }
     else
     {
         Alarm_Visible_flag.ecu_err = 0;
         TIME_CNT.ecu_err_count = 0;
     }

     if ( Alarm_Visible_flag.ecu_err == 1 )
     {
         error = 1;
		 
         if(Engine_Timing_Mark == 0)
         {
             ALARM_ENGINE2 = 1;
         }
         else
         {

             if( ReverseMark == 1)
             {
                 bing = 1;//蜂鸣器响
                 ALARM_ENGINE2 = 1;
             }
             else
             {
                 ALARM_ENGINE2 = 0;
             }
         }
     }
     else if( ECU_ERROR_IN == 0 )
     {
         ALARM_ENGINE2 = 1;
     }
     else if( ECU_ERROR_IN == 1 )
     {
         ALARM_ENGINE2 = 0;
     }
#endif

#if 0
   //电喷发动机故障
  if ( FaultFlag && FaultCode )     // 当有报警时，报警每秒减1
  {
    FaultFlag--;
    FaultCnt = 1;
	if( Flip_Flag == 1)
	{
		ALARM_ENGINE = 1;
		bing =1;
	}
	else
	{
		ALARM_ENGINE = 0;
		bing = 0;
	}
  }
  else
  {
      ALARM_ENGINE = 0;
      if(FaultCnt==1)
      {
          FaultCnt = 0;
          FaultWrPtr = 0; //欧三故障报警清零
          FaultFlag = 0;
          FaultCode = 0;
          FaultSPN = 0;
          FaultFMI = 0;
          FaultOC = 0;
//          SendFlag.fault_falg = 1;
      }
  }

    if( TIME_CNT.no_can>= 5 )
    {
//        CanState = 1;
//        AlarmText[14] = 0;  //清除无转速报警
//        AlarmText[5] = 0;//清楚冷却液报警
//        NO_CAN;
//        error = 1;
        Engine_Speed = 0;
        WaterTemp = 0;
        OilPressure = 0;
        OIL_WATER_CAN = 0;
        PREHEAT_CAN = 0;
    }
//    else
//    {
//        CanState = 0;
////        AlarmText[18] = 0;
//    }

#endif





    /*****************空滤长响程序***************************************/
//   if (bing == 1)
//	{
//		BEEP_ON;
//	}
//	else
//	{
//		BEEP_OFF;
//	}
	
}
